﻿package mortal.game.view.relive
{
    import Message.DB.Tables.*;
    import Message.Public.*;
    import __AS3__.vec.*;
    import baseEngine.modifiers.*;
    import com.gengine.core.frame.*;
    import com.gengine.global.*;
    import com.gengine.resource.*;
    import com.mui.controls.*;
    import com.mui.core.*;
    import com.mui.display.*;
    import extend.language.*;
    import flash.events.*;
    import flash.geom.*;
    import frEngine.*;
    import frEngine.effectEditTool.temple.*;
    import frEngine.pools.*;
    import frEngine.primitives.object2d.*;
    import mortal.common.*;
    import mortal.common.global.*;
    import mortal.component.gconst.*;
    import mortal.component.window.*;
    import mortal.game.*;
    import mortal.game.control.*;
    import mortal.game.events.*;
    import mortal.game.manager.*;
    import mortal.game.manager.window3d.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.resource.tableConfig.*;
    import mortal.game.scene3D.map3D.util.*;
    import mortal.game.scene3D.model.data.*;
    import mortal.game.scene3D.model.player.*;
    import mortal.game.scene3D.model.pools.*;
    import mortal.game.scene3D.player.entity.*;
    import mortal.game.utils.*;
    import mortal.game.view.common.*;
    import mortal.game.view.guide.*;
    import mortal.mvc.core.*;
    import mortal.mvc.interfaces.*;

    public class RelivePanelBase extends Window
    {
        protected var _txtName:GTextFiled;
        protected var _line:ScaleBitmap;
        protected var _txtKill:GTextFiled;
        private var _sec2:SecTimerView;
        protected const BgHeight:int = 253;
        protected const BgWidth:int = 1047;
        protected var _bg:GBitmap;
        protected var _isLoading:Boolean = false;
        protected var _bodyPlayer:ActionPlayer;
        protected var _rect3d:Rect3DObject;
        protected var _effectPlayerArray:Vector.<EffectPlayer>;
        protected var _hangPlayer:ActionPlayer;
        protected var _tnpc:TNpc;
        protected var sx:int = 290;
        protected var sy:int = 70;
        protected var _killerInfo:SEntityKillerInfo;
        protected var _img2d:Img2D;

        public function RelivePanelBase(param1:ILayer = null)
        {
            this._effectPlayerArray = new Vector.<EffectPlayer>;
            super(param1);
            this.layer = LayerManager.npcDialogLayr;
            return;
        }// end function

        public function set killerInfo(param1:SEntityKillerInfo) : void
        {
            this._killerInfo = param1;
            var _loc_2:* = ClockManager.instance.nowDate;
            var _loc_3:* = _loc_2.hours + ":" + _loc_2.minutes + ":" + _loc_2.seconds;
            var _loc_4:* = RolePlayer.instance.x2d;
            var _loc_5:* = RolePlayer.instance.y2d;
            var _loc_6:* = Game.sceneInfo.sMapDefine.name;
            var _loc_7:* = _loc_6 + " (" + _loc_4.toString() + ", " + _loc_5.toString() + ")";
            var _loc_8:String = "玩家";
            if (param1.isBoss)
            {
                _loc_8 = "怪物";
            }
            if (param1.name == "" || param1.name == null)
            {
                _loc_8 = "";
            }
            if (!param1.isBoss && !GameMapUtil.curMapState.isTreasureHunt)
            {
                this._txtKill.htmlText = Language.getStringByParam(21053, _loc_3, _loc_8, param1.name, _loc_7);
            }
            else
            {
                this._txtKill.htmlText = Language.getStringByParam(21054, _loc_3, _loc_7);
            }
            return;
        }// end function

        public function setLeftTime(param1:int) : void
        {
            return;
        }// end function

        override public function show(param1:int = 0, param2:int = 0) : void
        {
            super.show(param1, param2);
            this.onStageResize();
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this._tnpc = NPCConfig.instance.getInfoByCode(1100000);
            if (_closeBtn != null)
            {
                DisplayUtil.removeMe(_closeBtn);
                _closeBtn = null;
            }
            this._bg = UIFactory.gBitmap(null, 0, 0);
            var _loc_1:* = GlobalStyle.textFormatBai;
            _loc_1.size = 16;
            _loc_1.letterSpacing = 3;
            this._txtName = UIFactory.gTextField(Language.getString(21055), this.sx + 62, this.sy - 21, 200, 25, this, _loc_1);
            _loc_1 = GlobalStyle.textFormatBai;
            _loc_1.size = 16;
            _loc_1.letterSpacing = 3;
            this._txtKill = UIFactory.gTextField(Language.getString(21056), this.sx + 62, this.sy + 8, 700, 25, this, _loc_1);
            _loc_1 = GlobalStyle.textFormatHuang2;
            _loc_1.size = 13;
            this._sec2 = UIFactory.secTimeView(Language.getString(21057), 485, 51, 300, 26, this, _loc_1);
            this._sec2.timeOutHandler = this.timeAutoRelieve;
            var _loc_2:* = Math.ceil((ReliveController.serverRoleDeadTime - FrameManager.flashFrame.getTime() + 120000) / 1000);
            _loc_2 = Math.min(_loc_2, 120);
            this._sec2.setLeftTime(_loc_2);
            this._sec2.filters = [FilterConst.glowFilter];
            this._isLoading = true;
            LoaderHelp.addResCallBack(ResFileConst.relivePanel, this.resGotHandler);
            this._txtKill.configEventListener(TextEvent.LINK, this.linkTextHandler);
            return;
        }// end function

        private function timeAutoRelieve() : void
        {
            if (BuyPropWin.isViewShow)
            {
                BuyPropWin.instance.hide();
            }
            GameProxy.sceneProxy.relive(ERevival._ERevivalPoint);
            return;
        }// end function

        private function linkTextHandler(event:TextEvent) : void
        {
            if (this._killerInfo == null || this._killerInfo.isBoss)
            {
                return;
            }
            event.stopImmediatePropagation();
            Dispatcher.dispatchEvent(new DataEvent(EventName.LookPlayerInfo, this._killerInfo.entityId));
            return;
        }// end function

        protected function resGotHandler() : void
        {
            if (isDisposed)
            {
                return;
            }
            this._isLoading = false;
            this._line = UIFactory.bg(this.sx, this.sy, 660, 10, this, ImagesConst.relive_SplitLine);
            this._bg.bitmapData = GlobalClass.getBitmapData(ImagesConst.relive_BG);
            this._img2d = new Img2D(null, this._bg.bitmapData, new Rectangle(0, 0, this._bg.bitmapData.width, this._bg.bitmapData.height), true);
            this.addNpc3d();
            this.onStageResize();
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            super.disposeImpl(param1);
            this._effectPlayerArray.length = 0;
            if (this._hangPlayer)
            {
                this._bodyPlayer.unHang(this._hangPlayer);
                this._hangPlayer.dispose();
                this._hangPlayer = null;
            }
            if (this._bodyPlayer)
            {
                this._bodyPlayer.dispose();
                this._bodyPlayer = null;
            }
            this._txtName.dispose(param1);
            this._txtName = null;
            this._txtKill.dispose(param1);
            this._txtKill = null;
            if (this._line != null)
            {
                this._line.dispose(param1);
                this._line = null;
            }
            if (this._bg != null)
            {
                this._bg.dispose(param1);
                this._bg = null;
            }
            if (this._sec2 != null)
            {
                this._sec2.stop();
                this._sec2.dispose(param1);
                this._sec2 = null;
            }
            return;
        }// end function

        public function onStageResize() : void
        {
            if (this._isLoading)
            {
                return;
            }
            if (this.parent == null)
            {
                return;
            }
            this.y = Global.stage.stageHeight - this.BgHeight - 180;
            this.x = (Global.stage.stageWidth - this._bg.width) / 2;
            return;
        }// end function

        protected function addNpc3d() : void
        {
            stageResize();
            if (this._tnpc == null)
            {
                return;
            }
            this._rect3d = Rect3DManager.instance.getRect3dByWindow(this);
            if (!this._rect3d)
            {
                this._rect3d = Rect3DManager.instance.registerWindow(false, new Rectangle(0, 0, this._img2d.width - 5, this._img2d.height - 6), this);
            }
            Rect3DManager.instance.windowShowHander(null, this);
            this._rect3d.addImg(this._img2d);
            this.updateToCurNpc();
            return;
        }// end function

        protected function updateToCurNpc() : void
        {
            var _loc_1:Array = null;
            var _loc_2:Vector.<Array> = null;
            var _loc_3:int = 0;
            var _loc_4:Array = null;
            var _loc_5:Array = null;
            var _loc_6:EffectPlayer = null;
            if (this._rect3d && this._tnpc)
            {
                if (this._bodyPlayer == null)
                {
                    this._bodyPlayer = FrObjectPool.getObject(ActionPlayer, this);
                }
                if (this._bodyPlayer.meshUrl != this._tnpc.mesh && this._bodyPlayer.animUrl != this._tnpc.bone)
                {
                    this._bodyPlayer.load(this._tnpc.mesh, this._tnpc.bone, this._tnpc.texture, this._rect3d.renderList);
                    if (this._tnpc.hangModel)
                    {
                        _loc_1 = this._tnpc.hangModel.split("#");
                        if (_loc_1.length >= 4)
                        {
                            if (!this._hangPlayer)
                            {
                                this._hangPlayer = FrObjectPool.getObject(ActionPlayer, this);
                                this._hangPlayer.changeAction(ActionName.Stand);
                                this._hangPlayer.selectEnabled = true;
                                this._hangPlayer.timerContorler = TimeControler.defaultTimeControler;
                                this._hangPlayer.play();
                            }
                            this._hangPlayer.load(_loc_1[0], _loc_1[1], _loc_1[2], this._rect3d.renderList);
                            this._hangPlayer.hangBoneName = _loc_1[3];
                            this._bodyPlayer.hang(this._hangPlayer);
                        }
                    }
                    if (this._tnpc.selfEffect)
                    {
                        _loc_2 = GameStrUtil.alzToArray(this._tnpc.selfEffect);
                        _loc_4 = _loc_2[0];
                        _loc_5 = _loc_2[1];
                        _loc_3 = 0;
                        while (_loc_3 < _loc_4.length)
                        {
                            
                            if (this._effectPlayerArray.length > _loc_3)
                            {
                                _loc_6 = this._effectPlayerArray[_loc_3];
                                this._bodyPlayer.unHang(_loc_6);
                                _loc_6.dispose();
                            }
                            _loc_6 = EffectPlayerPool.instance.getEffectPlayer(_loc_4[_loc_3], null, this._rect3d.renderList, false);
                            this._effectPlayerArray[_loc_3] = _loc_6;
                            if (_loc_5.length > _loc_3)
                            {
                                _loc_6.hangBoneName = _loc_5[_loc_3];
                            }
                            if (_loc_6.temple is TempleRole)
                            {
                                (_loc_6.temple as TempleRole).setRoleParams(this._bodyPlayer, null, null);
                            }
                            else
                            {
                                this._bodyPlayer.hang(_loc_6);
                            }
                            _loc_6.play(PlayMode.ANIMATION_LOOP_MODE);
                            _loc_3++;
                        }
                    }
                }
                this._bodyPlayer.changeAction(ActionName.Stand);
                this._bodyPlayer.play();
                this._bodyPlayer.scaleValue = 2;
                this._rect3d.addObject3d(this._bodyPlayer, 210, 215);
            }
            return;
        }// end function

    }
}
